package utils

import javax.inject.Provider

import play.api.db.slick.{ DatabaseConfigProvider, DbName, SlickApi }
import slick.basic.{ BasicProfile, DatabaseConfig }
import slick.jdbc.JdbcProfile

class ArcherNamedDatabaseConfigProvider(slickApi: SlickApi)
  extends Provider[DatabaseConfigProvider] {
  lazy val get: DatabaseConfigProvider = new DatabaseConfigProvider {
    def get[P <: BasicProfile]: DatabaseConfig[P] =
      slickApi.dbConfig[P](DbName("archer"))
  }
}

class CommonDB(dbProvider: ArcherNamedDatabaseConfigProvider) {
  protected val dbConfig: DatabaseConfig[JdbcProfile] =
    dbProvider.get.get[JdbcProfile]

  /** The Slick profile extracted from `dbConfig`. */
  final lazy val profile: JdbcProfile = dbConfig.profile // field is lazy to avoid early initializer problems.
  /** The Slick database extracted from `dbConfig`. */
  final def db: JdbcProfile#Backend#Database = dbConfig.db
}
/*class LoggingDatabaseConfigProvider(slickApi: SlickApi) extends Provider[DatabaseConfigProvider] {
  lazy val get: DatabaseConfigProvider = new DatabaseConfigProvider {
    def get[P <: BasicProfile]: DatabaseConfig[P] = slickApi.dbConfig[P](DbName("loggingdb"))
  }
}

class LoggingDB(dbProvider: LoggingDatabaseConfigProvider) {
  protected val dbConfig: DatabaseConfig[JdbcProfile] = dbProvider.get.get[JdbcProfile]
  /** The Slick profile extracted from `dbConfig`. */
  final lazy val profile: JdbcProfile = dbConfig.profile // field is lazy to avoid early initializer problems.
  /** The Slick database extracted from `dbConfig`. */
  final def db: JdbcProfile#Backend#Database = dbConfig.db
}*/
